package com.pattern.behavioural;

/**
 * @author Ping
 * @date 2022/5/10 15:27
 **/
public class CommandDemo {
    public static void main(String args[]) {
        AirConditionInvoker invoker = new AirConditionInvoker(
                                          new AirConditionOnCommand(
                                                   new AirCondition()
                                          )) ;
        invoker.pressOn();
    }
}


class AirCondition {
    public void switchOn() {
        System.out.println("the airCondition was power on.") ;
    }
}

/**
 * key concept.
 */
interface Command {
    public void execute() ;
    public void undo() ;
}

/**
 * one concrete Command (ie. a button on controller)
 */
class AirConditionOnCommand implements Command {
    private AirCondition airCondition ;

    public AirConditionOnCommand(AirCondition airCondition) {
        this.airCondition = airCondition;
    }

    @Override
    public void execute() {
        airCondition.switchOn();
    }

    @Override
    public void undo() {

    }
}
class AirConditionInvoker {
    private Command airConditionCommand ;

    public AirConditionInvoker(Command airConditionCommand) {
        this.airConditionCommand = airConditionCommand;
    }
    public void pressOn() {
        airConditionCommand.execute();
    }
}